//
//  CallCarView.swift
//  JiaoZiTaxi
//
//  Created by Hu Gang on 2022/10/10.
//

import AVFoundation
import SwiftUI
import MapKit

struct CallCarDistanceView: View {
    
    @Binding var needDistanceInfo: Bool
    
    @State var fanwei : Double = 3
    
    var callCar: ((Int) -> Void)?

    var body: some View {
        VStack {
        // 背景点击区域 - 覆盖整个屏幕
        Color.clear
           .contentShape(Rectangle()) // 使整个区域可点击
           .onTapGesture {
               withAnimation {
                   needDistanceInfo = false
               }
           }
           .allowsHitTesting(needDistanceInfo) // 仅在显示信息时响应点击
            Spacer()
            VStack (spacing: 30){
                HStack (){
                    Spacer()
                    Text("更改呼叫范围").foregroundColor(.black).font(.system(size: 18,weight: .bold))
                    Spacer()
                }
                
                VStack (spacing: 50){
                    Text("点击-减小呼叫出租车范围，点+增加范围")
                        .foregroundColor(Color.black)
                        .font(.system(size: 14))
                    StepperView(value:self.$fanwei)
                }
                Button {
                    if let call = self.callCar {
                        call(Int(self.fanwei))
                    }
                    self.needDistanceInfo = false;
                } label: {
                    Text("立即呼叫").foregroundColor(Color.white).frame(maxWidth: .infinity,minHeight: 48)
                }
                .background(
                    RoundedRectangle(cornerRadius: 6.0)
                        .fill(Color.themeColor())
                )
                
                .padding(.horizontal,15)
                .padding(.bottom,20)
            }
//            .padding(.horizontal,15)
            .padding(.vertical,20)
            .cornerRadius(10)
            .background(.linearGradient(Gradient(colors: [Color(hex: "#F8FFF8"),Color(hex: "#FCFBE4")]), startPoint: .leading, endPoint: .trailing))
            .clipShape(RoundedTopRectangle(cornerRadius: 20))
            
        }
     
    }

}
